<%@ page language="java" import="java.util.*,com.beans.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>admin_role</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	
	<script type="text/javascript" src="js/jquery-1.8.0.js"></script> 
	<script type="text/javascript">
		$(function(){
			$("#ch_checkall,#top_ch_checkall").click(function(){
				if(this.checked){
					$("input[name=ck_id]").attr("checked","checked");
				}else{
					$("input[name=ck_id]").removeAttr("checked");
				}		
			});
					
			$("table tr").mouseover(function(){
				$(this).css("background","#D3EAEF");
				$(this).siblings().css("background","white");
			});
		});
		
		//分页的“转到”功能
		function subForm(pageIndex){
			document.form1.action="AdminServlet.do?flag=manage&pageIndex="+pageIndex;
			document.form1.submit();
		}
		
		//删除用户，将状态设为0，在列表里不显示
		//用ajax验证删除的是不是自己，不是才能发送请求
		//ajax验证可以保证不回发，不刷新当前页
		function del(id){
			if(confirm('确定要删除吗')){
				var currentAdminId=${session_admin.id};  //取到Session中的 admin 的 id
				if(currentAdminId==''){
					alert("当前用户的session已失效!请重新登录");
					window.top.location.href = "${pageContext.request.contextPath}/login.jsp";
				}
				else{
					if(currentAdminId==id){
						alert("不能删除自已!");
					}
					else{
						window.location.href="${pageContext.request.contextPath}/AdminServlet.do?flag=del&id="+id;
					}
				}
			}
		}

	</script>

	<link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/maintable.css">

  </head>
  
  <body>
	 <div class ="div_title">
		<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理人员基本信息列表</span></div>
	 </div>
	 
	 <form action="RoleServlet.do"  name="form1" method="post">
		 <table class="main_table">
		     <tr>
	 			    <th>账号</th> 	
	 			    <th>状态</th>	
	 			    <th>用户角色</th>  
	 			    <th>最后更新日期</th> 	
	 			    <th>操作</th>
	 		</tr>
	 		
	 		<c:forEach var="admin" items="${adminRoleList }">
	 			<tr>
	 				<td>${admin.adminName }</td>	
	 				<td>
						<c:choose>
							<c:when test="${admin.state==1 }">正常</c:when>
							<c:when test="${admin.state==2 }">已锁定</c:when>
						</c:choose>
					</td>	
	 				<td>${admin.roleName }</td>	
	 				<td>${admin.editDate}"</td>	
	 				<td>
	 					<c:choose>
							<c:when test="${admin.state==1 }"><a href="RoleServlet.do?flag=assign&id=${admin.id }">角色分配</a> </c:when>
						</c:choose>
	 				</td>
	 			</tr>
	 		</c:forEach>
		</table>
		<div class="div_page" >
			  <div class="div_page_left">    共
			  	有 <label>${page.rowCount }</label> 条记录，当前第 <label>${page.pageIndex }</label> 页，共 <label>${page.pageCount }</label> 页	
			  </div>		
			  <div class="div_page_right" > 	 
			  	<c:choose>
			  		<c:when test="${page.hasPre }">
			  			<a href="RoleServlet.do?flag=listadmin&pageIndex=1">首页</a>
			  			<a href="RoleServlet.do?flag=listadmin&pageIndex=${page.pageIndex-1 }">上一页</a>  &nbsp;  &nbsp;  &nbsp;  &nbsp;
			  		</c:when>
			  		<c:otherwise>
			  			 首页
		  	 			 上一页
			  		</c:otherwise>
			  	</c:choose>
			  	
			  	<c:choose>
			  		<c:when test="${page.hasNext }">
			  			<a href="RoleServlet.do?flag=listadmin&pageIndex=${page.pageIndex+1 }">下一页</a>
			  			<a href="RoleServlet.do?flag=listadmin&pageIndex=${page.pageCount }">尾页</a>  &nbsp;  &nbsp;  &nbsp;  &nbsp;
			  		</c:when>
			  		<c:otherwise>
			  			 下一页 
		  	 		   	尾页
			  		</c:otherwise>
			  	</c:choose>
		  	    <button onclick="javascript:subForm(${param.pageIndex})">转到</button>
	  	        <input type="text" name="pageIndex" id="pageIndex" value="${page.pageIndex }" /> 页
		  	</div>	
		</div>
	 </form>
  </body>
</html>
